sacktankluafandomcom-20200214-history
Community Curator/Source/TSWRes Game1
Test Mode function GT.TestMode() draw.setscreen(1) local DrObjInLev = Draw.ObjectsInLevel local Sac = ObjTab6 CreateMode = false draw.tracktouches(Nil, SacMove, Nil) for k, v in ipairs(LuaCorTab) do local Ok, Func = Sandbox.Load(v) if Ok then LogicCoroutinesk = coroutine.create(Func) else print("Error loading coroutine "..k..",", Func) end end for i=1, math.huge do if PlayerOutOfLives then return end local OldTime = sys.gettime() CamX, CamY = Sac"X" - ((SizeX/2)/Zoom), -(Sac"Y"+Sac"YVol"*.95) + ((SizeY/2)/Zoom) draw.doevents() GT.GameHandleFrame() draw.beginframe() Draw.BGs.Default() Draw.Level() --Draw.Thermometer(DrThV(), 24, 24, 48, SizeY-24) Draw.DPad(64, SizeY-96, PlayCol1, PlayCol2) local NewTime = sys.gettime() local Frame = (NewTime-OldTime) Draw.StatusBar(Frame) draw.endframe() --CG() --CG("stop") sys.sleep(((1/FR)-(NewTime-OldTime))*1000) end end function Emitter(Obj, EmitX, EmitY) Obj"X", Obj"Y" = EmitX, EmitY ObjTab#ObjTab+1 = Obj end function GT.StringAttach(Obj1, Obj2) end -- Handles a single object's collision function GT.ObjectCollision(ObjKey) --[[ local LC, RC, UC, DC = 0,0,0,0 local Object = ObjTabObjKey local ObjX, ObjY = Object"X", Object"Y" local TRec = TRec Object"XVol" = Object"XVol"/1.03 local Collisions = 0 for k,v in ipairs(ObjTab) do if TRec(v"X"-(v"Size"*4), v"Y"-(v"Size"*4), v"X"+ (v"Size"*4), v"Y"+(v"Size"*4), ObjX, ObjY) then if k ~= ObjKey and v"NoCollide" ~= true then local Col, L, R, U, D = CRec(v"X"-v"Size", v"Y"-v"Size", v"X" + v"Size", v"Y" + v"Size", ObjX-Object"Size", (ObjY)-Object"Size", ObjX+Object"Size", ObjY+Object"Size", Object"XVol", Object"YVol") --print(ObjKey.."Colision?" ..k .. tostring(Col), L, R, U, D) if ObjKey 6 then if type(v"CreTab") "table" then local CT = v"CreTab" local Dead = TRec(CT"X", CT"Y", CT"X" + CT"Size", CT"Y" + CT"Size", ObjX, ObjY) if Dead then CT"Dead" = true end end end if Col then LC, RC, UC, DC = LC+L, RC+R, UC+U, DC+D if ObjKey 6 then if v"Lethal" "Elec" or v"Lethal" "Gas" then print("Sackboy") GT.SackDie() end end Collisions = Collisions + 1 if Object"Weight" > v"Weight"*2 then table.remove(ObjTab, k) return end end end end end --print(ObjKey.." Collisions: "..Collisions, LC, RC, UC, DC) if Collisions 0 then if Object"Mat" "Peach Floaty" then Object"YVol" = -math.abs(math.min(Object"YVol"+.4, 9.8)) end Object"YVol" = math.min(Object"YVol"+.4, 9.8) Object"X" = ObjX+Object"XVol" Object"Y" = ObjY+Object"YVol" else if LC>0 then Object"XVol" = -math.abs(Object"XVol"/.298) end if RC>0 then Object"XVol" = math.abs(Object"XVol"/.298) end if UC>0 then Object"YVol" = math.abs(Object"YVol"*.2) end if UC 0 and DC 0 then Object"YVol" = math.abs(math.min(Object"YVol"+.4, 9.8)) end if DC>0 then Object"YVol" = -math.abs(Object"YVol"*.2) end --Object"XVol" = -(Object"XVol"/1.02) --Object"YVol" = Object"YVol"*.5 Object"X" = ObjX+Object"XVol" Object"Y" = ObjY-Object"YVol" Object"RotRad" = Object"RotRad" + Object"RVol" end return Collisions ]] end -- Handles the level collision function GT.HandleCollisions() --[Collision = GT.ObjectCollision for k,v in ipairs(ObjTab) do if v["Dynam" true and v"NoCollide" ~= true then if v"CreTab" then GT.CreatureObject(ObjTabk) end if v"Attach" then end Collision(k) end end]] end -- Handles the Logic Coroutines so they can run function GT.HandleCoroutines() for k, v in ipairs(LogicCoroutines) do print("Coroutine "..k, coroutine.status(v)) if coroutine.status(v) ~= "dead" then local Ok, Error = coroutine.resume(LogicCoroutinesk) if collectgarbage("count")*1024 > (120*1024*1024) then print("Low Memory", ObjRes.BytesPlus(collectgarbage("count")*1024)) collectgarbage() end if collectgarbage("count")*1024 > (128*1024*1024) then error("Too much memory usage", ObjRes.BytesPlus(collectgarbage("count")*1024)) end if not Ok then print("Coroutine "..k..tostring(Ok), Error) end else table.remove(LogicCoroutines, k) end end end function GT.HandleSackboyUnderWater() --print("Sackboy Underwater") if SackboyBreath nil then SackboyBreath = LevelTab"SackboyBreath" or FR * 20 else SackboyBreath = SackboyBreath - 1 if SackboyBreath < FR*10 then sys.alert("tock") end if SackboyBreath < 0 then sys.alert("neg") -- SackboyBreath = nil GT.SackDie() end end end function GT.HandleSackboy() local Sackboy = ObjTab6 assert(Sackboy) --print(Sackboy"Y", LevelTab"WaterLevel") if Sackboy"Y" > LevelTab"WaterLevel" then -- UnderwaterPhysics GT.HandleSackboyUnderWater() else SackboyBreath = nil end end -- Handles a frame of Gameplay. function GT.GameHandleFrame() GT.HandleCollisions() GT.HandleSackboy() GT.HandleCoroutines() end -- Creature Stuff -- -- Create A Creature table. function GT.CreateCreTab() local CreTab = {} CreTab"SackResp" = "Ignore" CreTab"Speed" = 1 CreTab"JumpFrame" = 0 CreTab"JumpPwr" = 1 CreTab"JumpInt" = 1 CreTab"JumpPhs" = 1 CreTab"X" = 0 CreTab"Y" = 0 CreTab"Size" = 24 return CreTab end function GT.CreatureObject(Obj, Key) local CreTab = Obj"CreTab" if CreTab"Dead" then table.remove(ObjTab, Key) return end Obj"XVol" = CreTab"Speed" * 4 CreTab"JumpFrame" = CreTab"JumpFrame" + 1 if CreTab"JumpFrame" > 20 * CreTab"JumpPhs" then print(CreTab"JumpFrame") Obj"Y" = Obj"Y" -1 Obj"YVol" = -(3 * CreTab"JumpPwr") if CreTab"JumpFrame" > 20 * CreTab"JumpPhs" + CreTab"JumpInt" then CreTab"JumpFrame" = 0 end end end return